﻿namespace AiQiuQuan.Sport.Core
{
    /// <summary>
    /// 返回数据格式统一
    /// </summary>
    public class UnaryResult
    {
        /// <summary>
        /// 状态：0 正常；非0异常
        /// </summary>
        public int Code { get; set; }

        /// <summary>
        /// 异常信息
        /// </summary>
        public string Msg { get; set; } = string.Empty;

        /// <summary>
        /// 新框架标志
        /// </summary>
        public int Version { get; set; } = 1;

        /// <summary>
        /// 成功状态数据
        /// </summary>
        public static UnaryResult<TData> Succeed<TData>(TData data)
        {
            return new UnaryResult<TData> { Code = 0, Data = data };
        }

        /// <summary>
        /// 成功状态数据
        /// </summary>
        public static UnaryResult Succeed()
        {
            return new UnaryResult { Code = 0 };
        }

        /// <summary>
        /// 错误信息
        /// </summary>
        public static UnaryResult Faild(int statusCode, string msg)
        {
            return new UnaryResult { Code = statusCode, Msg = msg };
        }

        /// <summary>
        /// 包装数据
        /// </summary>
        public static UnaryResult<TData> From<TData>(int statusCode, TData data, string msg = "")
        {
            return new UnaryResult<TData> { Code = statusCode, Data = data, Msg = msg };
        }
    }

    /// <summary>
    /// 返回数据格式统一
    /// </summary>
    /// <typeparam name="TData">承载数据类型</typeparam>
    public class UnaryResult<TData> : UnaryResult
    {
        /// <summary>
        /// 承载数据
        /// </summary>
        public TData Data { get; set; }

        /// <summary>
        /// ctor
        /// </summary>
        public UnaryResult() { }

        /// <summary>
        /// ctor
        /// </summary>
        public UnaryResult(TData data)
        {
            Data = data;
        }
    }

    /// <summary>
    /// 数据格式统一
    /// </summary>
    internal class UnaryResultObj : UnaryResult
    {
        /// <summary>
        /// 承载数据
        /// </summary>
        public object Data { get; set; }
    }
}
